package org.brisling.authorize.shiro;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter;
import org.apache.shiro.web.servlet.ShiroHttpServletRequest;

public class PassThruAuthenticationFilterExtends extends PassThruAuthenticationFilter {
	
	@Override
	protected void redirectToLogin(ServletRequest request,ServletResponse response) throws IOException{
		
				
		ShiroHttpServletRequest hrequest = (ShiroHttpServletRequest)request;
		String uri = hrequest.getRequestURI();
		
		if(uri!=null){
			String[] uriArr = uri.split("/");
			if(uriArr.length>=2){
				String redirectLong = String.format("/%1$s", uriArr[1]);
				this.setLoginUrl(redirectLong);
			}
		}
		
		super.redirectToLogin(request, response);
	}

}
